package wfmanage.action;

import java.util.ArrayList;
import java.util.Map;

import org.apache.struts2.ServletActionContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.MyLog;

import edu.wfmanage.models.Lookup;

public class ModifyLookup extends ActionSupport {
	private int lookup_id=0;
	int i=0;
	private String table="";
	private String name = "";
	private int is_current = 0;
	private String submit="";
	Lookup lookup =new Lookup();
    private ArrayList<Lookup> allValues = new ArrayList<Lookup>();

	public String execute() throws Exception {
		Map session = ActionContext.getContext().getSession();
		session = ActionContext.getContext().getSession();
		table=(String)session.get("table");
		MyLog.log("here"+session.get("table"));
     	if (submit.equals("")) {
			MyLog.log("In ModifyLookup.execute().......");
			lookup = Lookup.findOne(table," where "+table+"_id = " + lookup_id);
			lookup.setTable(table);
	        	MyLog.log("name:"+lookup.getName());
	        	MyLog.log("iscurrent:"+lookup.getIs_current());
	        	MyLog.log("table:"+lookup.getTable());
			MyLog.log("Lookup_id to be modified is :"+lookup_id);
			return "initial";
		}
	else{
		lookup.setTable(table);
		lookup.setId(lookup_id);
		lookup.setName(name);
		lookup.setIs_current(is_current);
		lookup.update(table);
		MyLog.log(lookup_id+" lookup details are successfully updated...!");
		this.allValues = lookup.find(table,"");
		return "success";
		}
	}

	public Lookup getLookup() {
		return lookup;
	}

	public void setLookup(Lookup lookup) {
		this.lookup = lookup;
	}

	public int getLookup_id() {
		return lookup_id;
	}

	public void setLookup_id(int lookup_id) {
		this.lookup_id = lookup_id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getIs_current() {
		return is_current;
	}

	public void setIs_current(int is_current) {
		this.is_current = is_current;
	}

	public String getSubmit() {
		return submit;
	}

	public void setSubmit(String submit) {
		this.submit = submit;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public ArrayList<Lookup> getAllValues() {
		return allValues;
	}

	public void setAllValues(ArrayList<Lookup> allValues) {
		this.allValues = allValues;
	}
}
